using System;
using System.Configuration;
using System.Data;
using digit.Core;

namespace SMS.ServiceManager
{
    public class SportTeamCupManager
    {
        #region CONSTRUCTORS
        static SportTeamCupManager()
        {
            _data = new SportTeamCupData(Util.GetConnectionString("SMSSERVICE"));
            _error = "";
        }
        #endregion

        #region ATTRIBUTES
        private static SportTeamCupData _data;
        private static string _error;
        #endregion

        #region PROPERTIES
        public static string ErrorMessage
        {
            get
            {
                return _error;
            }
        }

        #endregion

        #region METHODS
        public static bool Insert(int relateId, int cupId, int teamId)
        {
            _error = "";
            try
            {
                object[] values = new object[2];
                values[0] = cupId;
                values[1] = teamId;

                return _data.Insert(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Insert(SportTeamCupInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[2];
                values[0] = info.CupID;
                values[1] = info.TeamID;

                return _data.Insert(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(int relateId, int cupId, int teamId)
        {
            _error = "";
            try
            {
                object[] values = new object[3];
                values[0] = relateId;
                values[1] = cupId;
                values[2] = teamId;

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(SportTeamCupInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[3];
                values[0] = info.RelateID;
                values[1] = info.CupID;
                values[2] = info.TeamID;

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(int relateId)
        {
            _error = "";
            try
            {
                object[] values = { relateId };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(SportTeamCupInfo info)
        {
            _error = "";
            try
            {
                object[] values = { info.CupID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static SportTeamCupInfo Select(int relateId)
        {
            _error = "";
            try
            {
                object[] values = { relateId };
                DataTable dTable = _data.Select(values);
                if (dTable.Rows.Count < 1) return null;


                SportTeamCupInfo info = new SportTeamCupInfo(dTable.Rows[0]);
                return info;
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectAll()
        {
            _error = "";
            try
            {
                return _data.SelectAll();
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectAllForRelate(byte bytStatus)
        {
            _error = "";
            try
            {
                return _data.SelectAllForRelate(bytStatus);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        #endregion

    }
}